本章介紹:
先在程式碼插入以下程式後執行。
import _ "net/http/pprof"
func main() {
go func() {
http.ListenAndServe("0.0.0.0:8080", nil)
}()
}
$go tool pprof http://127.0.0.1:8080/debug/pprof/heap
-> 輸入top
->輸入web可以看到圖形
(pprof) top
Showing nodes accounting for 1.50MB, 100% of 1.50MB total
flat flat% sum% cum cum%
1.50MB 100% 100% 1.50MB 100% golang.org/x/net/webdav.(*memFile).Write
0 0% 100% 1.50MB 100% github.com/swaggo/files.init.8
go tool pprof http://localhost:6060/debug/pprof/profile?seconds=60
1.先下載 go set
go get github.com/securego/gosec/cmd/gosec@v2.2.0
2.輸出報告(可選格式)
gosec -fmt=json -out=results.json ./...
gosec -fmt=html -out=results.html ./... *三個點